package practise.TicTacToeTomek;

import java.util.Scanner;


public class Bata1
{	
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		
		int rount = sc.nextInt()+1;
		for(int i=1; i<rount; i++)
		{
			int[][] num = new int[4][4];
			boolean flag = false;
			
			for(int j=0; j<4; j++)
			{
				char[] ch = sc.next().toCharArray();
				
				for(int k=0; k<4; k++)
				{
					if(ch[k] == 'X')
						num[j][k] = 1;
					else if(ch[k] == 'O')
						num[j][k] = -1;
					else if(ch[k] == 'T')
						num[j][k] = 0;
					else
					{
						num[j][k] = 100;
						flag = true;
					}
				}
			}
			
			int n1 = num[0][0] + num[1][1] + num[2][2] + num[3][3];
			int n2 = num[0][3] + num[1][2] + num[2][1] + num[3][0];
			
			if(n1 == -3 || n1 == -4 || n2 == -3 || n2 == -4)
			{
				System.out.println("Case #" + i + ": O won");
				continue;
			}
			
			if(n1 == 3 || n1 == 4 || n2 == 3 || n2 == 4)
			{
				System.out.println("Case #" + i + ": X won");
				continue;
			}
			
			boolean flag2 = false;
			for(int j=0; j<4; j++)
			{
				n1 = num[j][0] + num[j][1] + num[j][2] + num[j][3];
				n2 = num[0][j] + num[1][j] + num[2][j] + num[3][j];
				
				if(n1 == -3 || n1 == -4 || n2 == -3 || n2 == -4)
				{
					System.out.println("Case #" + i + ": O won");
					flag2 = true;
					break;
				}
				
				if(n1 == 3 || n1 == 4 || n2 == 3 || n2 == 4)
				{
					System.out.println("Case #" + i + ": X won");
					flag2 = true;
					break;
				}
			}
			
			if(!flag2)
				if(flag)
				{
					System.out.println("Case #" + i + ": Game has not completed");
				}
				else
				{
					System.out.println("Case #" + i + ": Draw");
				}
		}
	}
}
